#度中心度
import networkx as nx

# 读取数据集
G = nx.read_edgelist('email-Network.txt', create_using=nx.DiGraph())

#department_labels因为只有一个‘部门’属性用字典的方式存储
department_labels = {}
with open('email-Department.txt', 'r') as file:
    for line in file:
        #split()默认以空格的方式分割
        node, label = line.strip().split()
        department_labels[node] = label

#print(department_labels)
# 将部门标签信息添加到节点属性中
nx.set_node_attributes(G, department_labels, 'department')


#度中心度
# degree_centrality = nx.degree_centrality(G)
# for i in range(len(degree_centrality)):
#     print(degree_centrality[str(i)])

# 入度中心度
# in_degree_centrality = nx.in_degree_centrality(G)
# print(in_degree_centrality)
# for i in range(len(in_degree_centrality)):
#     print(in_degree_centrality[str(i)])


# 出度中心度
# out_degree_centrality = nx.out_degree_centrality(G)
# for i in range(len(out_degree_centrality)):
#     print(out_degree_centrality[str(i)])


#接近中心度
# close_centrality = nx.closeness_centrality(G)
# for i in range(len(close_centrality)):
#     print(close_centrality[str(i)])

# 介数中心性
# betweenness_centrality = nx.betweenness_centrality(G, normalized = True,endpoints = False)
# for i in range(len(betweenness_centrality)):
#     print(betweenness_centrality[str(i)])


#特征向量中心性
eigenvector_centrality = nx.eigenvector_centrality(G)
for i in range(len(eigenvector_centrality)):
    print(eigenvector_centrality[str(i)])

